<?php


namespace app\admin\controller;


use app\common\controller\BaseController;
use think\App;
use think\db\Where;
use app\admin\model\TaskRecord as taskRecordModel;

class TaskRecord extends BaseController
{
    protected $model;

    public function __construct(App $app, taskRecordModel $record)
    {
        parent::__construct($app);
        $this->model = $record;
    }

    /**
     * @return mixed
     * 任务订单列表
     */
    public function query()
    {
        $where = new Where();
        $memberId = input('member_id');
        !empty($memberId) && $where['receiver_id'] = $memberId;
        $field = "id,id expiredTime,task_id task,receiver_id receiver_name
       ,finish_step,task_status,is_expired,create_time,post_time,finish_time";
        $page = input('page/d', 1);
        $pageSize = input('page_size/d', 10);
        $order = ['create_time' => 'DESC'];
        return $this->model->getList($where, $field, $order, $page, $pageSize);
    }

    /**
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * 详情
     */
    public function read()
    {
        return $this->model->getOne($this->params);
    }

    /**
     * @return array
     * 审核通过
     */
    public function enable()
    {
        try {
            return $this->model->changeStatus($this->params, 2);
        } catch (\Exception $ex) {
            return $this->returnException($ex);
        }
    }

    /**
     * @return array
     * 审核拒绝
     */
    public function disable()
    {
        try {
            return $this->model->changeStatus($this->params, 4);
        } catch (\Exception $ex) {
            return $this->returnException($ex);
        }
    }
}